package com.mc.servlet;

import com.mc.VO.MatchVO;
import com.mc.bean.Jury;
import com.mc.bean.MJ;
import com.mc.bean.Score;
import com.mc.service.MJService;
import com.mc.service.MatchVOService;
import com.mc.service.ScoreService;
import com.mc.service.impl.MJServiceImpl;
import com.mc.service.impl.MatchVOServiceImpl;
import com.mc.service.impl.ScoreServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * @author wangcf
 * @version 1.0
 * @Description 评委评分列表
 * @date 2023/2/17 10:17
 */
@WebServlet("/juryscorelist.action")
public class JuryScoreListServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        MatchVOService matchVOService = new MatchVOServiceImpl();
        ScoreService scoreService=new ScoreServiceImpl();
        MJService mjService=new MJServiceImpl();


        HttpSession session=req.getSession();
        Object obj=session.getAttribute("user");
        //获取评委的编号
        Jury jury=(Jury)obj;
        //去赛事评委关系表cha赛事编号
        List<MJ> mjList=mjService.findByJuryId(jury.getJuryid());
        //存这个评委参加的所有赛事的所有队伍
        List<MatchVO> matchVOList=new ArrayList<>();
        //通过赛事编号查赛事的队伍
        for(MJ mj:mjList){
            //查询这个赛事的所有队伍
            List<MatchVO> matchVOList1= matchVOService.findByMid(mj.getMid());
            //把所有队伍加入一个集合
            for (MatchVO matchVO:matchVOList1){

                //通过参赛编号和赛评编号查询是否有成绩
                Score score= scoreService.findByMatchCodeMJCode(matchVO.getMatchcode(),mj.getMjcode());
                //有
                if(score!=null){
                    matchVO.setScore(score.getScore());
                }
                matchVOList.add(matchVO);
            }
        }
        req.setAttribute("matchvolist",matchVOList);
       req.getRequestDispatcher("juryscorelist.jsp").forward(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
